/***************************************************************************
 *   Copyright (C) 2007 by Ulta (http://ultrasonic.home.pl)                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#ifndef GJPEG2K_H
#define GJPEG2K_H

#include <QImageIOHandler>
#include <QImage>
#include <QByteArray>

// ---------------------------------------------------------------------------
/*!
 * The QImageIOHandler subclass, performs I/O specific
 * to the JPEG 2000 image format.
*/
// ---------------------------------------------------------------------------
class GJpeg2kHandler : public QImageIOHandler
{
public:
        /*!
        * Handler constructor.
        */
    GJpeg2kHandler();
        /*!
        * Handler destructor.
        */
    ~GJpeg2kHandler();

        /*!
        * Determines if the image can be read from the device.
        *
        * Determines by:
        * - the image format is supported,
        * - the device can be read from,
        * - the initial header information suggests that the image can be read.
        *
        * @return true if an image can be read otherwise returns false
        */
    bool canRead() const;
        /*!
        * Read JPEG 2000 imgage.
        *
        * @param image image handler to store read image in
        * @return true if read operations went good otherwise false
        */
    bool read(QImage *image);
        /*!
        * Writes JPEG 2000 file.
        *
        * @param image image to compress into j2k file and write
        * @return true if read operations went good otherwise false
        */
    bool write(const QImage &image);
        /*!
        * Checks whether a JPEG 2000 image can be read from a given device.
        *
        * It simply checks that the input data contains the
        * magic number, 0x0d0a870a.
        *
        * @param device device from which the image suppose to be read
        * @return true if j2k image can be read form the device,
        *         otherwise returns false.
        */
    static bool canRead(QIODevice *device);
        /*!
        * Gives option value.
        *
        * @param option option which value will be returned
        * @return option value
        */
    QVariant option(ImageOption option) const;
        /*!
        * Sets options value.
        *
        * @param option option to set
        * @param value to set
        */
    void setOption(ImageOption option, const QVariant &value);
        /*!
        * Returns supperted options.
        *
        * Currently non of ImageOptions are supported, neither fast Size
        * detection couse in JPEG 2000 it requires reading hole image.
        *
        * @return true if option is supported otherwise false
        */
    bool supportsOption(ImageOption option) const;
    
private:
	
	QByteArray _bmpBuffer;
    
}; // class GJpeg2kHandler{}
// ---------------------------------------------------------------------------


#endif // !GJPEG2K_H


